package com.rj02.fist.shop.util;

import org.jdom.Document;
import org.jdom.Element;
import org.jdom.input.SAXBuilder;

import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

public class MyUtil {
    public static Map<String,String> readXML(String util) throws Exception{
        //读取配置文件xml
        Map<String,String> map = new HashMap<String,String>();
        SAXBuilder saxBuilder=new SAXBuilder();
        String path=MyUtil.class.getResource("/").getPath()+util;
        Document doc=saxBuilder.build(path);
        Element root=doc.getRootElement();
        System.out.println(root.getName());
        List<Element> list=root.getChildren();
        /*for(int i=0;i<list.size();i++) {
            System.out.println(list.get(i).getName());
        }
        */
        Iterator iter=list.iterator();
        while(iter.hasNext()){
            Element e = (Element) iter.next();
            System.out.println(e.getName()+"--------"+e.getText());
            map.put(e.getName(),e.getText());
        }
        return map;
    }

    public static void main(String[] args) {
        try {
            System.out.println(MyUtil.readXML("dao-config.xml"));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
